var enroll = {
    userName : ".enroll_input[name=userName]",
    password : ".enroll_input[name=password]",
    nickName : ".enroll_input[name=nickName]",
    email : ".enroll_input[name=email]",
    authCode : ".enroll_input[name=authCode]",
    submitButton : '.enroll_input[type=button]',
    enrollForm:'#enrollForm',
    userNameOK : false,
    passwordOK : false,
    emailOK : false,
    nickNameOK : false,
    authCodeOK : false
};
$(function() {

    $(enroll.userName).focus();
    basic.hover('.enroll_login', {
        "cursor" : "pointer",
        "text-decoration" : "underline",
        "color" : "#1170b2"
    }, {
        "cursor" : "default",
        "text-decoration" : "none",
        "color" : "#000000"
    });

    $(enroll.userName).bind('input propertychange', function() {
        var userNameReg = /^[a-zA-Z]{5,10}$/;
        var val = $(this).val();
        if (!userNameReg.test(val)) {

            $("#enroll_point").html("*用户名由5-10个英文字母组成");

            enroll.userNameOK = false;
            $(this).css({
                border : '2px solid red'
            });
        } else {
            $("#enroll_point").html("&nbsp");
            enroll.userNameOK = true;
            $(this).css({
                border : '1px solid gray'
            });
        }
    });
    $(enroll.password).bind('input propertychange', function() {
        var pwdReg = /^[a-zA-Z0-9_]{6,15}$/;
        var val = $(this).val();
        if (!pwdReg.test(val)) {
            $("#enroll_point").html("*密码由6-15个英文字母，数字和下划线组成");
            enroll.passwordOK = false;
            $(this).css({
                border : '2px solid red'
            });
        } else {
            $("#enroll_point").html("&nbsp;");
            enroll.passwordOK = true;
            $(this).css({
                border : '1px solid gray'
            });
        }
    });
    $(enroll.nickName).bind('input propertychange', function() {
        var nickNameReg = /^[a-zA-Z\u4e00-\u9faf]{2,8}$/;
        var val = $(this).val();
        if (!nickNameReg.test(val)) {
            $("#enroll_point").html("*昵称由2-8个英文字母和汉字组成");
            enroll.nickNameOK = false;
            $(this).css({
                border : '2px solid red'
            });
        } else {
            $("#enroll_point").html("&nbsp;");
            enroll.nickNameOK = true;
            $(this).css({
                border : '1px solid gray'
            });
        }
    });
    $(enroll.email).bind('input propertychange', function() {
        var emailReg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
        var val = $(this).val();
        if (!emailReg.test(val)) {
            $("#enroll_point").html("*请输入正确的Email");
            enroll.emailOK = false;
            $(this).css({
                border : '2px solid red'
            });
        } else {
            $("#enroll_point").html("&nbsp;");
            enroll.emailOK = true;
            $(this).css({
                border : '1px solid gray'
            });
        }
    });
    $(enroll.authCode).bind('input propertychange', function() {
        var authCodeReg = /^[a-zA-Z]{5}$/;
        var val = $(this).val();
        if (!authCodeReg.test(val)) {
            $("#enroll_point").html("*验证码由6个英文字母组成，不分大小写");
            enroll.authCodeOK = false;
            $(this).css({
                border : '2px solid red'
            });
        } else {
            $("#enroll_point").html("&nbsp;");
            enroll.authCodeOK = true;
            $(this).css({
                border : '1px solid gray'
            });
        }
    });

    $(enroll.submitButton).click(function() {

        var userNameReg = /^[a-zA-Z]{5,10}$/;
        var val = $(enroll.userName).val();
        if (userNameReg.test(val)) {
            enroll.userNameOK = true;
        } else {
            enroll.userNameOK = false;
        }

        var emailReg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
        val = $(enroll.email).val();
        if (emailReg.test(val)) {
            enroll.emailOK = true;
        } else {
            enroll.emailOK = false;
        }

        var pwdReg = /^[a-zA-Z0-9_]{6,15}$/;
        val = $(enroll.password).val();
        if (pwdReg.test(val)) {
            enroll.passwordOK = true;
        } else {
            enroll.passwordOK = false;
        }

        var nickNameReg = /^[a-zA-Z\u4e00-\u9faf]{2,8}$/;
        val = $(enroll.nickName).val();
        if (nickNameReg.test(val)) {
            enroll.nickNameOK = true;
        } else {
            enroll.nickNameOK = false;
        }

        var authCodeReg = /^[a-zA-Z]{5}$/;
        val = $(enroll.authCode).val();
        if (authCodeReg.test(val)) {
            enroll.authCodeOK = true;
        } else {
            enroll.authCodeOK = false;
        }

        if (!enroll.userNameOK) {
            $(enroll.userName).focus();
            $("#enroll_point").html("*用户名由5-10个英文字母组成");
            $(enroll.userName).css({
                border : '2px solid red'
            });
            return;
        } else {
            $(enroll.userName).css({
                border : '1px solid gray'
            });
        }

        if (!enroll.emailOK) {
            $(enroll.email).focus();
            $("#enroll_point").html("*请输入正确的Email");
            $(enroll.email).css({
                border : '2px solid red'
            });
            return;
        } else {
            $(enroll.email).css({
                border : '1px solid gray'
            });
        }

        if (!enroll.passwordOK) {
            $(enroll.password).focus();
            $("#enroll_point").html("*密码由6-15个英文字母，数字和下划线组成");
            $(enroll.password).css({
                border : '2px solid red'
            });
            return;
        } else {
            $(enroll.password).css({
                border : '1px solid gray'
            });
        }

        if (!enroll.nickNameOK) {
            $(enroll.nickName).focus();
            $("#enroll_point").html("*昵称由2-8个英文字母和汉字组成");
            $(enroll.nickName).css({
                border : '2px solid red'
            });
            return;
        } else {
            $(enroll.nickName).css({
                border : '1px solid gray'
            });
        }

        if (!enroll.authCodeOK) {
            $(enroll.authCode).focus();
            $("#enroll_point").html("*验证码由6个英文字母组成，不分大小写");
            $(enroll.authCode).css({
                border : '2px solid red'
            });
            return;
        } else {
            $(enroll.authCode).css({
                border : '1px solid gray'
            });
        }
        $(enroll.enrollForm).submit();
    });

    $(document).keydown(function(e) {
        if (e.keyCode == 13) {
            $(enroll.submitButton).trigger("click");
        }
    });
    
   basic.mouseover('#enrollAuthCodeImage',{
       cursor:'pointer'
   });
   $("#enrollAuthCodeImage").click(function() {
       $(this).attr('src',basic.addr+'enrollAuthCodeImage.html?d='+new Date().getTime());
       });
   
});

